//
//  TCLoginView.m
//  陶瓷
//
//  Created by 王戈 on 15/6/11.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "TCLoginView.h"

@interface TCLoginView ()

@property (weak, nonatomic) IBOutlet UILabel *levelLabel;
@property (weak, nonatomic) IBOutlet UIButton *addressBtn;

@property (weak, nonatomic) IBOutlet UIButton *favoriteBtn;
@property (weak, nonatomic) IBOutlet UIButton *messageBtn;
@property (weak, nonatomic) IBOutlet UIView *whiteLine;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end


@implementation TCLoginView

- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        
        UIImage *bgImage = [UIImage imageNamed:@"sidebar_bg@2x.jpg"];

        self.layer.contents = (id)bgImage.CGImage;
    }
    return self;
}

- (void)setIsLogin:(BOOL)isLogin {
    _isLogin = isLogin;
    _favoriteBtn.hidden = !isLogin;
    _messageBtn.hidden = !isLogin;

    _whiteLine.hidden = !isLogin;
    _addressBtn.hidden = !isLogin;
    _nameLabel.hidden = !isLogin;
    _levelLabel.hidden = !isLogin;
    _iconBtn.hidden = !isLogin;
    
    _loginBtn.hidden = isLogin;
}

- (IBAction)login:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(userLogin)]) {
        [self.delegate userLogin];
    }
}

- (void)setInfoDict:(NSDictionary *)infoDict {
    _infoDict = infoDict;
//    [_iconBtn sd_setImageWithURL: forState:UIControlStateNormal placeholderImage:];
    [_iconBtn sd_setBackgroundImageWithURL:[infoDict objectForKey:@"HeadImage"] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"touxiang_none.png"]];
    _iconBtn.layer.borderWidth = 1;
    _iconBtn.layer.borderColor = [UIColor blackColor].CGColor;
    _iconBtn.clipsToBounds = YES;
    _levelLabel.text = [infoDict objectForKey:@"Level"];
    _nameLabel.text = [infoDict objectForKey:@"NickName"];
    _nameLabel.font = [UIFont boldSystemFontOfSize:18];
    [self setNeedsLayout];
    [self layoutIfNeeded];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _iconBtn.layer.cornerRadius = _iconBtn.width/2;
}

- (IBAction)grayBtnClick:(UIButton *)sender {
    self.clickBlock(sender.currentTitle);
}


- (void)grayBtnClickWithBlock:(sendCilckInfoBlock)clickBlock {
    _clickBlock = clickBlock;
}


@end
